package mo.offer_special;

public class L004 {

    public int singleNumber(int[] nums) {
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            int total = 0;
            for (int num : nums) {
                total += ((num >> i) & 1);
            }
            if (total % 3 != 0) {
                ans = ans | (1 << i);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        //补码 最高位如果为1 则1后面的 取反并+1
        System.out.println(Integer.toBinaryString(-64));
        L004 test = new L004();
        System.out.println(test.singleNumber(new int[]{2,2,2,-1}));
    }

}
